/*
 * channel_launcher.cpp
 *
 */

#include <iostream>

#include "../channel_common/AgentIdManager.h"
#include "../channel_common/ChannelInterface.h"
#include "../IPC/ProcessAux.h"
#include "../common/Argv.h"
#include "../capa_servicios_distribuidos/QueueLauncher.h"
#include "../middleware/CommunicationVendedor.h"

int main()
{
	channel::ChannelInterface::create("cliente_pc");
	channel::ChannelInterface::create("vendedor_pc");

//	{
//		using namespace middleware;
//		ipc::MessageQueue<CommunicationVendedor::VendedorRequestStruct>::create(CommunicationVendedor::REQUEST_QUEUE_PATH,CommunicationVendedor::REQUEST_QUEUE_KEY_CLI_SIDE);
//		ipc::MessageQueue<CommunicationVendedor::VendedorReplyStruct>::create(CommunicationVendedor::REPLY_QUEUE_PATH,CommunicationVendedor::REPLY_QUEUE_KEY_CLI_SIDE);
//		ipc::MessageQueue<CommunicationVendedor::VendedorRequestStruct>::create(CommunicationVendedor::REQUEST_QUEUE_PATH,CommunicationVendedor::REQUEST_QUEUE_KEY_VEND_SIDE);
//		ipc::MessageQueue<CommunicationVendedor::VendedorReplyStruct>::create(CommunicationVendedor::REPLY_QUEUE_PATH,CommunicationVendedor::REPLY_QUEUE_KEY_VEND_SIDE);
//	}

	servicios_distribuidos::QueueLauncher::createDistributedQueue
	<middleware::CommunicationVendedor::VendedorRequestStruct>
	(middleware::CommunicationVendedor::REQUEST_QUEUE_PATH,
     middleware::CommunicationVendedor::REQUEST_QUEUE_KEY_CLI_SIDE,
     "cliente_pc",servicios_distribuidos::QUEUE_SEND);

	servicios_distribuidos::QueueLauncher::createDistributedQueue
	<middleware::CommunicationVendedor::VendedorRequestStruct>
		(middleware::CommunicationVendedor::REQUEST_QUEUE_PATH,
		 middleware::CommunicationVendedor::REQUEST_QUEUE_KEY_VEND_SIDE,
		 "vendedor_pc", servicios_distribuidos::QUEUE_RECV,1111);


	servicios_distribuidos::QueueLauncher::createDistributedQueue
	<middleware::CommunicationVendedor::VendedorReplyStruct>
	(middleware::CommunicationVendedor::REPLY_QUEUE_PATH,
     middleware::CommunicationVendedor::REPLY_QUEUE_KEY_CLI_SIDE,
     "cliente_pc",servicios_distribuidos::QUEUE_RECV,2222);

	servicios_distribuidos::QueueLauncher::createDistributedQueue
	<middleware::CommunicationVendedor::VendedorReplyStruct>
		(middleware::CommunicationVendedor::REPLY_QUEUE_PATH,
		 middleware::CommunicationVendedor::REPLY_QUEUE_KEY_VEND_SIDE,
		 "vendedor_pc",servicios_distribuidos::QUEUE_SEND,2222);


	{
		Argv args;
		args.pushArg("vendedor_pc");
		ProcessAux::launchProcess2("./out/channel_out_agente",1,args);
		ProcessAux::launchProcess2("./out/channel_in_agente",1,args);
	}

	{
			Argv args;
			args.pushArg("cliente_pc");
			ProcessAux::launchProcess2("./out/channel_out_agente",1,args);
			ProcessAux::launchProcess2("./out/channel_in_agente",1,args);
	}
	return 0;
}
